/*
 *  Copyright 2009 Allan Lykke Christensen.
 * 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */
package dk.i2m.netbeans.modules.doxia;

import java.awt.EventQueue;
import java.awt.Image;
import java.io.Serializable;
import org.netbeans.core.spi.multiview.MultiViewDescription;
import org.netbeans.core.spi.multiview.MultiViewElement;
import org.openide.util.HelpCtx;
import org.openide.windows.TopComponent;

/**
 * Description of the APT source editor.
 *
 * @author Allan Lykke Christensen
 */
public class AptSourceDescription implements MultiViewDescription, Serializable {

    private AptEditorSupport support;
    private AptSourceEditor editor;

    /**
     * Creates a new instance of {@link AptSourceView}.
     *
     * @param support
     *          Support for the {@link AptSourceEditor}
     */
    public AptSourceDescription(AptEditorSupport support) {
        this.support = support;
    }

    public int getPersistenceType() {
        return TopComponent.PERSISTENCE_ALWAYS;
    }

    public String getDisplayName() {
        return "Source";
    }

    public Image getIcon() {
        return null;
    }

    public HelpCtx getHelpCtx() {
        return null;
    }

    public String preferredID() {
        return "AptSourceDescription";
    }

    public MultiViewElement createElement() {
        return getEditor();
    }

    private AptSourceEditor getEditor() {
        assert EventQueue.isDispatchThread();

        if (editor == null) {
            editor = new AptSourceEditor(support);
        }
        return editor;
    }
}
